﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BLL;
using Models;

namespace GoShopping.tools
{
    /// <summary>
    /// Car1 的摘要说明
    /// </summary>
    public class Car1 : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            string caozuo = context.Request["caozuo"].ToString();
            switch (caozuo)
            {
                case "增":
                    addCar(context);
                         break;
                case "删":
                    delete(context);
                    break;
            }

        }
        /// <summary>
        /// 增加car
        /// </summary>
        /// <param name="context"></param>
        /// <exception cref="NotImplementedException"></exception>
        private void addCar(HttpContext context)
        {
            int goodsId = int.Parse(context.Request.Form["GoodsID"]);
            int userId = int.Parse(context.Request.Form["UserID"]);
            int num = int.Parse(context.Request.Form["Num"]);
            Models.Car car = new Models.Car();
            car.GoodsID = goodsId;
            car.UserID = userId;
            car.Num = num;
            bool res=CarBLL.addCarDLL(car);
            if (res)
            {
                context.Response.Write("{\"status\":\"添加成功！\"}");
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="context"></param>
        private void delete(HttpContext context)
        {
            int CarID = int.Parse(context.Request.QueryString["tyID"]);
            bool res=CarBLL.deleteByIDBLL(CarID);
            if (res)
            {
                context.Response.Write("{\"status\":\"删除成功！\"}");
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}